cmake_minimum_required(VERSION 3.10)

if(TARGET "pplnn_static")
    return()
endif()

add_library(pplnn_static STATIC IMPORTED)

# --------------------------------------------------------------------------- #

set(__PPLNN_PACKAGE_ROOTDIR__ "${CMAKE_CURRENT_LIST_DIR}/../../..")
set(__PPLNN_LINK_LIBRARIES__)

# --------------------------------------------------------------------------- #

# exported definitions

set(PPLNN_USE_X86 @PPLNN_USE_X86@)
set(PPLNN_USE_ARM @PPLNN_USE_ARM@)
set(PPLNN_USE_RISCV @PPLNN_USE_RISCV@)
set(PPLNN_USE_CUDA @PPLNN_USE_CUDA@)

set(PPLNN_INCLUDE_DIRS "${__PPLNN_PACKAGE_ROOTDIR__}/include")
set(PPLNN_LIBRARIES "pplnn_static")

# --------------------------------------------------------------------------- #

if(NOT TARGET "pplcommon_static")
    include(${CMAKE_CURRENT_LIST_DIR}/pplcommon-config.cmake)
endif()
list(APPEND __PPLNN_LINK_LIBRARIES__ "pplcommon_static")

if(PPLNN_USE_X86)
    if(NOT TARGET "pplkernelx86_static")
        include(${CMAKE_CURRENT_LIST_DIR}/pplkernelx86-config.cmake)
    endif()
    list(APPEND __PPLNN_LINK_LIBRARIES__ "pplkernelx86_static")
endif()

if(PPLNN_USE_ARM)
    if(NOT TARGET "pplkernelarmserver_static")
        include(${CMAKE_CURRENT_LIST_DIR}/pplkernelarmserver-config.cmake)
    endif()
    list(APPEND __PPLNN_LINK_LIBRARIES__ "pplkernelarmserver_static")
endif()

if(PPLNN_USE_CUDA)
    if(NOT TARGET "pplkernelcuda_static")
        include(${CMAKE_CURRENT_LIST_DIR}/pplkernelcuda-config.cmake)
    endif()
    list(APPEND __PPLNN_LINK_LIBRARIES__ "pplkernelcuda_static")
endif()

if(PPLNN_USE_RISCV)
    if(NOT TARGET "pplkernelriscv_static")
        include(${CMAKE_CURRENT_LIST_DIR}/pplkernelriscv-config.cmake)
    endif()
    list(APPEND __PPLNN_LINK_LIBRARIES__ "pplkernelcuda_static")
endif()

# TODO do not export protobuf
if(NOT TARGET "protobuf::libprotobuf-lite")
    include(${__PPLNN_PACKAGE_ROOTDIR__}/lib/cmake/protobuf/protobuf-config.cmake)
endif()
list(APPEND __PPLNN_LINK_LIBRARIES__ "protobuf::libprotobuf-lite")

# --------------------------------------------------------------------------- #

set_target_properties(pplnn_static PROPERTIES
    INTERFACE_LINK_LIBRARIES "${__PPLNN_LINK_LIBRARIES__}")

if(MSVC)
    set_target_properties(pplnn_static PROPERTIES
        IMPORTED_LOCATION "${__PPLNN_PACKAGE_ROOTDIR__}/lib/pplnn_static.lib"
        IMPORTED_LOCATION_DEBUG "${__PPLNN_PACKAGE_ROOTDIR__}/lib/pplnn_static.lib"
        IMPORTED_LOCATION_RELEASE "${__PPLNN_PACKAGE_ROOTDIR__}/lib/pplnn_static.lib")
else()
    set_target_properties(pplnn_static PROPERTIES
        IMPORTED_LOCATION "${__PPLNN_PACKAGE_ROOTDIR__}/lib/libpplnn_static.a"
        IMPORTED_LOCATION_DEBUG "${__PPLNN_PACKAGE_ROOTDIR__}/lib/libpplnn_static.a"
        IMPORTED_LOCATION_RELEASE "${__PPLNN_PACKAGE_ROOTDIR__}/lib/libpplnn_static.a")
endif()

# --------------------------------------------------------------------------- #

unset(__PPLNN_LINK_LIBRARIES__)
unset(__PPLNN_PACKAGE_ROOTDIR__)
